<template>
  <basic-container>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <avue-crud :data="levyResultData"
                 :option="tableoption"
                 :page="page"
                 :table-loading="tableLoading"
                 @size-change="sizeChange"
                 @current-change="currentChange"
                 @search-change="searchChange"
                 @search-reset="searchReset"
                 class="avuecrud">
        <template slot-scope="scope" slot="menu">
          <div class="menu-title" @click.stop="viewLevyDept(scope.row,scope.index)"
               v-if="scope.row.state=='1'||scope.row.state=='2'">
            <i class="iconfont iconview icon-primary"></i>
            <p class="menu-title-text">查看审核</p>
          </div>
        </template>
      </avue-crud>
    </div>
  </basic-container>
</template>

<script>
  import {getEndSubjectList} from "@/api/subject";

  export default {
    name: "todoEndsubjectfinished",
    created() {
      window.viewLevyDeptDetail = this.viewLevyDeptDetail;
      this.getResultList(this.page);
    },
    data() {
      return {
        headerData: {
          title: '结题申请'
        },
        levyResultData: [],
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        tableoption: {
          page: true,
          menuWidth: 120,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
          index: true,
          indexWidth:70,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          keyId: "id",
          column: [
            {
              label: "结题申请名称",
              prop: "title",
              cell: true
            },{
              label: "申请名称",
              prop: "titleLike",
              search: true,
              hide: true,
              cell: true,
              slot: true
            },
            {
              label: "结题申请说明",
              width: 320,
              prop: "description",
              cell: true
            },
            {
              label: "申请时间",
              width: 110,
              prop: "applyTime",
              cell: true,
              formatter: function (row, value, label, column) {
                if (row.applyTime != null) {
                  var data = row.applyTime.split(' ');
                  return data[0];
                }
              },
            },
            {
              label: "状态",
              width: 80,
              prop: "state",
              cell: true,
              formatter: function (row, value, label, column) {
                if (row.state == '0') {
                  return "<font color='red'>" + "申请结题" + "</font>";
                } else if (row.state == '1') {
                  return "<font color='#DCA450'>" + "不同意" + "</font>";
                } else if (row.state == '2') {
                  return "<font color='#7EBE50'>" + "同意" + "</font>";
                }
              }
            }
          ]
        },
        tableLoading: false,
        titleLikeSearch:''
      }
    },
    methods: {
      // 课题详情跳转
      viewLevyDept(row) {
        let src = `/levyFeedback/detail/${row.applyId}`;
        this.$router.push({
          path: src,
          query: {
            toDoOrnot: '1',
            subjectDeptId: row.subjectDeptId
          }
        })
      },
      // 课题详情跳转
      viewLevyDeptDetail(collectionId) {
        let src = `/levyFeedback/detail/${collectionId}`;
        this.$router.push({
          path: src,
          query: {
            targetId: row.targetId,
            toDoOrnot: '1',
          }
        })
      },
      levyDelete(row) {
        this.$confirm("确定删除此课题征集吗?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          levyDelete(row.collectionId).then(response => {
            if (response.data.code == 0) {
              this.$notify({
                title: '成功',
                message: '删除成功',
                type: 'success',
                duration: 2000
              });
              this.$router.go(0);
            }
          })
        })
      },
      currentChange(currentPage) {
        var page = this.page;
        page.currentPage = currentPage;
        let params = {
          titleLike:this.titleLikeSearch,
        };
        this.getResultList(page,params);
      },
      sizeChange(pageSize) {
        var page = this.page;
        page.pageSize = pageSize;
        let params = {
          titleLike:this.titleLikeSearch,
        };
        this.getResultList(page,params);
      },
      getResultList(page, params) {
        getEndSubjectList(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
          states: '1,2',
          collectionId: this.$route.params.id,
        },params)).then(response => {
          this.levyResultData = response.data.data.records;
          this.page.total = response.data.data.total;
        })
      },
      /**
       * 刷新回调
       */
      searchReset() {
        this.titleLikeSearch = '';
        let params = {
          titleLike:this.titleLikeSearch,
        };
        this.getResultList(this.page,params);
      },
      //搜索回调
      searchChange (params) {
        this.page.currentPage = 1
        this.getResultList(this.page, this.dealSearchParam(params));
      },
      // 处理搜索过滤
      dealSearchParam(params) {
        if (params.titleLike) {
          params.titleLike = params.titleLike;
        }
        this.titleLikeSearch = params.titleLike;
        return params;
      },
      // 发起课题征集跳转
      subjectLevy() {
        let src = `/subjectLevy/detail/${this.$route.params.id}`;
        this.$router.push({
          path: src
        })
      },
      // 增加课题跳转
      addSubject() {
        let src = `/addSubject/detail/${this.$route.params.id}`;
        this.$router.push({
          path: src
        })
      },
    }
  }
</script>

<style lang="scss" scoped>
  .card-body {
    padding: 10px;
    min-height: 400px
  }

  /deep/ .avue-crud__menu {
    min-height: 0px;
  }
</style>
